package com.tool_stdy.ConcurrencyModel;

import com.google.common.collect.Lists;

import java.util.List;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * Created by yan_li on 2016/11/11.
 */
public class OtherTest {

    private static CountDownLatch latch = new CountDownLatch(5000);


    public static void runJob(int i) {
        System.out.println(i);
        latch.countDown();
    }


    public static void main(String[] args) throws InterruptedException {
        List<Integer> lists = Lists.newArrayList();
        ExecutorService executor = Executors.newFixedThreadPool(3);
        long start =System.currentTimeMillis();
        for (int i = 0; i < 5000; i++) {
            lists.add(i);
        }
        for (int i = 0; i < lists.size(); i++) {
            final int finalI = i;
            executor.execute(new Runnable() {
                @Override
                public void run() {
                    runJob(finalI);
                }
            });
        }
        latch.await();
        System.out.println("userd:"+(System.currentTimeMillis()-start));
    }
}
